package com.sf.protal.controller;

import com.sf.protal.pojo.Msg;
import com.sf.protal.pojo.UmsAdmin;
import com.sf.protal.service.UmsAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/admin")
public class UmsAminController {
	@Autowired
	UmsAdminService umsAdminService;

	@RequestMapping({"/login"})
	public String showLogin() {
		return "admin/login";
	}

	@RequestMapping({"/register"})
	public String showRegister(){
		return "admin/register";
	}

	@RequestMapping({"/msg"})
	public String showMsg(){
		return "admin/msg";
	}

	@RequestMapping({"/index"})
	public String showIndex(){
		return "admin/index";
	}

	@RequestMapping({"/adv"})
	public String showAdv(){
		return "admin/adv";
	}

	@RequestMapping(value = "/login",method = RequestMethod.POST)
	public String login(Model model, UmsAdmin umsAdmin){
		UmsAdmin admin = umsAdminService.login(umsAdmin);
		if(admin!=null){
			model.addAttribute("admin",admin);
			return "admin/index";
		}else {
			model.addAttribute("msg","您的登录信息有误");
			return "admin/login";
		}
	}
}
